package com.xquant.pricing.calc.service.impl.otcOption;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.xquant.common.engine.xPP.request.CalcEngineParam;
import com.xquant.common.engine.xPP.request.CalcPricingParam;
import com.xquant.common.engine.xPP.request.Instrument;
import com.xquant.pricing.calc.entity.RequestCodeEnum;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Auther: B946
 * @Date: 09/04/2020 14:06
 * @Description:
 */
@Component
public class ReadFixingDatesServiceImpl4OtcOption extends CalcCommonService4OtcOption {

    @Override
    public String getSupportedRequestCode() {
        return RequestCodeEnum.READ_FIXINGDATES.getCode();
    }


    @Override
    public CalcEngineParam getCalcPricingParamByCfgId(CalcEngineParam param, String cfgId) {
        Instrument instrument = param.getInstrument();
        cfgId = getDefaultCfgId(cfgId);
        if(StringUtils.isBlank(cfgId)) {
            return null;
        }
        CalcEngineParam ret = new CalcEngineParam();
        ret.setCalcPricingParam(new CalcPricingParam());
        // 合约定价参数
        Map<String, Object> contractParam = getContractCfg(instrument, cfgId, getUnderlyIds(instrument));
        ret.getCalcPricingParam().setCalcPPCode(MapUtils.getString(contractParam, "DLL_NAME"));
        String diyParam = MapUtils.getString(contractParam, "DIY_PARAM");
        try {
            if(diyParam != null){
                JSONObject customPricingParam = JSON.parseObject(diyParam);
                ret.getCalcPricingParam().setCustomPricingParam(customPricingParam.get("customPricingParam"));
            }
        } catch (Exception ex) {

        }
        return ret;
    }
    @Override
    public CalcEngineParam getCalcPricingParamByCfgIdWarpperWithInterpolation(CalcEngineParam param, String cfgId) {
        return getCalcPricingParamByCfgId(param,cfgId);
    }
}
